package com.sky.controller.users;

import com.sky.context.BaseContext;
import com.sky.dto.ReserveOnDayDTO;
import com.sky.dto.TeacherDTO;
import com.sky.dto.TeacherPageQueryDTO;
import com.sky.entity.Museum;
import com.sky.entity.Teacher;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.MuseumService;
import com.sky.service.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.*;

import javax.management.relation.RelationSupport;
import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("/teacher")
@Api(tags = "医师相关接口")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;

    @GetMapping("/getAll")
    @ApiOperation(value = "查询所有医师接口")
    public List<Teacher> getTeacherList(){
        List<Teacher> teacherList = teacherService.TeacherList();
        return teacherList;
    }

    @GetMapping
    @ApiOperation(value = "根据日期查询医师接口")
    public List<Teacher> getTeacherByData(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate day){
        List<Teacher> teacherList=teacherService.selectByDay(day);
        return teacherList;
    }

    @GetMapping("/page")
    @ApiOperation(value = "分页查询医师接口")
    public Result<PageResult> pageSelect(TeacherPageQueryDTO teacherPageQueryDTO){
        PageResult pageResult = teacherService.pageQuery(teacherPageQueryDTO);
        return Result.success(pageResult);
    }

    @PostMapping("/reserve")
    @ApiOperation(value = "医师预约接口")
    public Result reserve(@RequestBody ReserveOnDayDTO reserveOnDayDTO){
        TeacherDTO teacherDTO=new TeacherDTO();
        Teacher teacher=teacherService.getOne(reserveOnDayDTO.getTerId());
        BeanUtils.copyProperties(teacher,teacherDTO);
        teacherDTO.setTerTime(reserveOnDayDTO.getDay());
        teacherService.reserveTeacher(teacherDTO);
        return Result.success();
    }

    @GetMapping("/getOne/{id}")
    @ApiOperation(value = "查看某个医师详情接口")
    public Result<Teacher> getOne(@PathVariable Long id){
        Teacher teacher=teacherService.getOne(id);
        return Result.success(teacher);
    }

    @GetMapping("/reserve/getAll")
    @ApiOperation(value = "查询已预约医师接口")
    public Result<List<Teacher>> getAllReserveTeacher(){
        List<Teacher> reserveTeacherList=teacherService.selectAllReserveTeacher();
        return Result.success(reserveTeacherList);
    }


    @DeleteMapping("/delete")
    @ApiOperation(value = "移除已预约医师接口")
    public Result deleteReserveTeacher(@RequestBody ReserveOnDayDTO reserveOnDayDTO){
        teacherService.deleteReserveTeacher(reserveOnDayDTO);
        return Result.success();
    }
}
